package com.quanquan.store.controller;

import com.quanquan.store.request.StoreLabelRequest;
import com.quanquan.store.service.LabelService;
import enums.ResCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import web.response.ResultBody;

import java.util.List;

/**
 * @ClassName:StoreLabelController
 * @Description:TODO
 * @Author:xiongjunbao
 * @Date:2019/7/19 10:24
 * @Version 1.0
 */
@RestController
@RequestMapping("/label")
public class LabelController {

    private final LabelService labelService;

    @Autowired
    public LabelController(LabelService labelService) {
        this.labelService = labelService;
    }


    /**
     * 新增标签
     *
     * @param request
     */
    @PostMapping("/save_label")
    public ResultBody saveLabel(@RequestBody StoreLabelRequest request) {
        boolean flag = labelService.saveLabel(request);
        if (flag) {
            return new ResultBody(ResCodeEnum.SUCCESS.getCode(), "SUCCESS");
        }
        return new ResultBody(ResCodeEnum.FAIL.getCode(), "FAIL");
    }
    /**
     * 标签列表
     *
     * @param request
     */
    @PostMapping("/label_list")
    public ResultBody labelList(@RequestBody StoreLabelRequest request) {
        List<Object> objectList = labelService.findAllLabel(request);
        if (objectList.size() <= 0) {
            return new ResultBody(ResCodeEnum.NO_DATA.getCode(), "暂无数据");
        }
        return new ResultBody(ResCodeEnum.SUCCESS.getCode(), "SUCCESS", objectList);
    }

    /**
     * 标签列表(后台)
     *
     * @param request
     */
    @PostMapping("/label_list_management")
    public ResultBody labelListManagement(@RequestBody StoreLabelRequest request) {
        return new ResultBody(ResCodeEnum.SUCCESS.getCode(), "SUCCESS", labelService.allLabelManagement(request));
    }

    /**
     * 标签列表(后台绑定商户使用)
     *
     * @param request
     */
    @PostMapping("/no_dis_label_list_management")
    public ResultBody noDisLabelListManagement(@RequestBody StoreLabelRequest request) {
        return new ResultBody(ResCodeEnum.SUCCESS.getCode(), "SUCCESS", labelService.noDisLabelManagement(request));
    }

    /**
     * 标签详情（后台）
     *
     * @param request
     */
    @PostMapping("/query")
    public ResultBody query(@RequestBody StoreLabelRequest request) {
        return new ResultBody(ResCodeEnum.SUCCESS.getCode(), "SUCCESS", labelService.query(request));
    }

    /**
     * 标签详情（后台）
     *
     * @param request
     */
    @PostMapping("/update_label")
    public ResultBody updateStoreLabel(@RequestBody StoreLabelRequest request) {
        boolean flag = labelService.updateStoreLabel(request);
        if (flag){
            return new ResultBody(ResCodeEnum.SUCCESS.getCode(), "SUCCESS");
        }
        return new ResultBody(ResCodeEnum.FAIL.getCode(), "FAIL" );
    }

    /**
     * 标签详情（后台）
     *
     * @param request
     */
    @PostMapping("/delete_label")
    public ResultBody deleteLabel(@RequestBody StoreLabelRequest request) {
        boolean flag = labelService.deleteLabel(request);
        if (flag){
            return new ResultBody(ResCodeEnum.SUCCESS.getCode(), "SUCCESS");
        }
        return new ResultBody(ResCodeEnum.FAIL.getCode(), "FAIL" );
    }



}
